package com.hok.misc.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;

public class DBTest {
	static int j = 0;
	public static void main(String[] args) throws InterruptedException {
		InertXdr.insertGsmTmp();
//		new Thread(new InsertExcuter()).start();
//		while(true) {
//			int count = selectGprs();
//			if(count == 200000) {
//				break;
//			}
//			Thread.sleep(500);
//		}
	}
	
	public static void batchThreadInsert()  {
		long start = System.currentTimeMillis();
		for (int i = 0; i < 10; i++) {
			new Thread(new InsertExcuter()).start();
		}
		System.out.println("final:" + (System.currentTimeMillis() - start) + " ms");
	}
	
	static class InsertExcuter implements Runnable {

		public void run() {
//			ConnectDB.batchInsertToMysql();
			InertXdr.insertGprs();
//			System.out.println(j++);
		}
	}
	
	public static int selectGprs() {
		//	insert into :tmpTableName<sql> (select t.*, '' REDO_CONDITION_ID from :tableName<sql> t where :whereSql<sql>)
			Connection connection = ConnectDB.getOracleconnection();
			System.out.println(connection);
			Calendar time = Calendar.getInstance();
			time.set(Calendar.DAY_OF_MONTH, 29);
			String sql = "select count(*) from  gprs_20110928";
			Statement st = null;
			try {
				st = connection.createStatement();
				long start = System.currentTimeMillis();
				boolean flag = st.execute(sql);
				ResultSet rs = st.getResultSet();
				int size = 0;
				if(rs.next()) {
				    size = rs.getInt(1);
					System.out.println("current insert rows:" + size);
				}
				System.out.println("use:" + (System.currentTimeMillis() - start) + " " + flag);
				return size;
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				try {
					if (st != null) {
						st.close();
					}
					if (connection != null) {
						connection.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return 0;
		}
}

